package com.witframework.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
import org.apache.taglibs.standard.tag.common.core.OutSupport;

public class PageParameterTag extends TagSupport{
	private String name;
	private String defaultValue="";
	@Override
    public int doStartTag() throws JspException {
        if (name == null) {
            throw new JspException("The required parameterName attribute is not set");
        }        
        try {
            String value=pageContext.getRequest().getParameter(name);            
            OutSupport.out(pageContext, true,value==null?defaultValue:value);            
        } catch (IOException e) {
            // ignored
        }
        return EVAL_PAGE;
    }
	
	

	public void setName(String name) {		
		this.name = name;		
		try {
			this.name=(String) ExpressionEvaluatorManager.evaluate("name",name,String.class,this,pageContext);
		} catch (JspException e) {
			e.printStackTrace();
		}
	}

	
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
		try {
			this.defaultValue=(String) ExpressionEvaluatorManager.evaluate("defaultValue",defaultValue,String.class,this,pageContext);
		} catch (JspException e) {
			e.printStackTrace();
		}
	}
}
